package io.bluefw.blueui;

import java.io.IOException;
import java.io.InputStream;

import javax.ws.rs.WebApplicationException;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;

import io.bluefw.blueui.dsl.Pagelet;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class BlueUIRender {
    public static StringBuffer render(InputStream input) throws IOException, WebApplicationException {
		try {
			ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
			Pagelet pagelet = mapper.readValue(input, Pagelet.class);
			return pagelet.render();
			
		} catch (IOException e) {
			log.error(e.getMessage());
			throw new WebApplicationException(e);
		}
    }
}
